package com.jacobson.huobi.common.expansion

import com.google.gson.Gson
import java.lang.Exception

val jsonMapper = Gson()

fun Any.toJson(): String {
    return jsonMapper.toJson(this) ?: "{}"
}

inline fun <reified T> String.fromJson(): T? {
    return try {
        jsonMapper.fromJson<T>(this, T::class.java)
    } catch (e: Exception) {
        null
    }
}